{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Plotting functions with error bands\"\"\"\n",
    "import numpy as np\n",
    "from vedo.pyplot import plot\n",
    "from vedo import *\n",
    "embedWindow('2d')\n",
    "\n",
    "# Make up same data\n",
    "x = np.arange(0, 6, 0.1)\n",
    "y = 2+2*np.sin(2*x)/(x+1)\n",
    "ye= y**2 / 10\n",
    "miny = np.min(y-ye)\n",
    "idx = np.argmax(y)\n",
    "\n",
    "# Plot the two variables, return a Plot(Assembly) object:\n",
    "plt = plot(x,y,\n",
    "           yerrors=ye,\n",
    "           xtitle='time in seconds',\n",
    "           ytitle='y oscillation [a.u.]',\n",
    "           ylim=(0.5, 5),\n",
    "           aspect=4/3,     # aspect ratio (any float = x_size/y_size)\n",
    "           errorBand=True, # join errors on y into an error band\n",
    "           lc=\"k\",         # line color\n",
    "           ec=\"r\",         # error band color\n",
    "           la=0.6,         # error and line alphas\n",
    "           pad=0.0,        # tight margins, no padding\n",
    ")\n",
    "\n",
    "# Add a grey transparent rectangle to represent an exclusion region:\n",
    "plt += Rectangle([1,0.5], [2.7,5], alpha=0.2, c='k')\n",
    "\n",
    "# Add some text and latex formula\n",
    "plt += Text3D(\"excluded\", s=0.2, c='k').rotateZ(20).pos(1.3, 3.7)\n",
    "plt += Latex(r\"y(t)=2+2\\cdot\\frac{\\sin(2t)}{(t+1)}\", pos=(4.7, 4.7), s=.8, c='db')\n",
    "\n",
    "# Add a star marker at maximum of function (at z=0.1, so it stays on top):\n",
    "plt += Marker('*', pos=(x[idx], y[idx], 0.1), c='blue')\n",
    "\n",
    "# Add a dashed line for the minimum\n",
    "plt += DashedLine([x[0], miny], [x[-1], miny])\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
